package com.yl.module.file.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.common.core.domain.Result;
import com.yl.module.file.domain.FileType;
import com.yl.module.file.domain.dto.FileTypeDTO;
import com.yl.module.file.domain.vo.FileTypeVO;
import com.yl.module.file.service.FileTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 文件类型表 Controller控制层
 * @author makejava
 * @date 2024-06-11 16:43:57
 */
@Slf4j
@RestController
@Api(tags = "文件类型")
@RequestMapping("/fileType")
@Validated
public class FileTypeController {
    /**
     * 文件类型表 Service
     */
    @Autowired
    public FileTypeService fileTypeService;

    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有", notes = "")
	public Result<List<FileTypeVO>> getAll() {
		//Long userId = UserContext.getUser().getUserId();
		//System.out.println("用户id:"+userId);
		List<FileTypeVO> result = fileTypeService.getAll();
		return Result.ok(result);
	}

    @GetMapping("/getPage")
    @ApiOperation(value = "分页查询", notes = "")
	public Result<Page<FileType>> getByPage(
		@Validated FileTypeDTO dto
	) {
		Page<FileType> result = fileTypeService.getPage(dto);
		return Result.ok(result);
	}

    @GetMapping("/getByKey")
    @ApiOperation(value = "通过主键查询", notes = "")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "int"),
	})
	public Result<FileTypeVO> getByKey(
			@NotNull(message = "参数id不能为空")Integer id
	) {
		FileTypeVO result = fileTypeService.getByKey(id);
		return Result.ok(result);
	}

	@PostMapping("/add")
    @ApiOperation(value = "添加", notes = "")
	public Result<Integer> add(
		@RequestBody @Validated FileTypeDTO dto
	) {
		Integer result = fileTypeService.add(dto);
		return Result.ok(result);
	}

	@PostMapping("/upd")
    @ApiOperation(value = "通过主键修改", notes = "")
	public Result upd(
		@RequestBody @Validated FileTypeDTO dto
	) {
		fileTypeService.upd(dto);
		return Result.ok();
	}


}

